package org.wzq.base;

import android.app.Application;
import android.content.Context;
import android.provider.Settings;
import android.telephony.TelephonyManager;
import org.json.JSONException;
import org.json.JSONObject;

/**
 * project:
 * author: wzq
 * date: 2014/8/8
 * description:设备信息，唯一标识
 */
public class DeviceInfo {
    public static String deviceUuid = null;
    public static String release;//os版本
    public static String model;//设备型号
    public static String imei;//imei

    private static String deviceInfo = null;
    private static JSONObject deviceInfoJson = null;

    public static JSONObject getDeviceInfoJson() {
        return deviceInfoJson;
    }
    public static String getInfo() {
        return deviceInfo;
    }
//
    public static String getDeviceUuid(){
        return deviceUuid;
    }

    private DeviceInfo() {
    }

    public static void init() {
        Application application = BaseApplication.getInstance();
        release = android.os.Build.VERSION.RELEASE;
        model = android.os.Build.MODEL;
        deviceUuid = Settings.Secure.getString(application.getContentResolver(), android.provider.Settings.Secure.ANDROID_ID);
        // imei
        TelephonyManager tm = (TelephonyManager) application.getSystemService(Context.TELEPHONY_SERVICE);
        imei = tm.getDeviceId();
        //
        JSONObject sb = new JSONObject();
        try {
            sb.put("release", release);
            sb.put("model", model);
            sb.put("imei", imei);
            sb.put("deviceUuid",deviceUuid);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        deviceInfoJson = sb;
        deviceInfo = sb.toString();

    }
}
